package com.huadi.bili_hot.service;

import com.huadi.bili_hot.dao.mapper.RecommendMapper;
import com.huadi.bili_hot.entity.Recommend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class RecommendServiceImpl implements RecommendService {

    @Autowired
    private RecommendMapper recommendMapper;

    @Override
    public List<Recommend> getBangumiRec() {
         List<Recommend> tmplist = recommendMapper.selectBangumiRec();
         List<Recommend> BangumiRec = new ArrayList<>();
         for(int i=0;i<5;i++){
             Random random = new Random();
             int num = random.nextInt(tmplist.size());
             BangumiRec.add(tmplist.get(num));
             tmplist.remove(num);
         }
         return BangumiRec;
    }

    @Override
    public List<Recommend> getTvRec() {
        List<Recommend> tmplist = recommendMapper.selectTvRec();
        List<Recommend> TVRec = new ArrayList<>();
        for(int i=0;i<5;i++){
            Random random = new Random();
            int num = random.nextInt(tmplist.size());
            TVRec.add(tmplist.get(num));
            tmplist.remove(num);
        }
        return TVRec;
    }

    @Override
    public List<Recommend> getMovieRec() {
        List<Recommend> tmplist = recommendMapper.selectMovieRec();
        List<Recommend> MovieRec = new ArrayList<>();
        for(int i=0;i<5;i++){
            Random random = new Random();
            int num = random.nextInt(tmplist.size());
            MovieRec.add(tmplist.get(num));
            tmplist.remove(num);
        }
        return MovieRec;
    }

    @Override
    public List<Recommend> getBangumiRecList() {
        return recommendMapper.selectBangumiRec();
    }

    @Override
    public List<Recommend> getTvRecList() {
        return recommendMapper.selectTvRec();
    }

    @Override
    public List<Recommend> getMovieList() {
        return recommendMapper.selectMovieRec();
    }

    @Override
    public List<Recommend> getBestList() {
        return recommendMapper.selectBestList();
    }
}
